using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Toast.Extensions
{
    public static class CoreExtensions
    {
        public static string FormatWith(this string input, params string[] parms)
        {
            return string.Format(input, parms);
        }

        public static bool IsNullOrEmpty(this string input)
        {
            return string.IsNullOrEmpty(input);
        }

        public static string Join(this IEnumerable<string> list, string separator)
        {
            return string.Join(separator, list.ToArray());
        }

        public static bool IsValidUrl(this string input)
        {
            return string.IsNullOrEmpty(input);
        }

        public static T2 IfNotNull<T1, T2>(this T1 t, Func<T1, T2> func)
        {
            return t != null ? func(t) : default(T2);
        }

        public static void IfNotNull<T1>(this T1 t, Action<T1> func)
        {
            if (t != null) func(t);
        }

        public static bool IsAjaxRequest(this HttpRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            return ((request["X-Requested-With"] == "XMLHttpRequest") || ((request.Headers != null) && (request.Headers["X-Requested-With"] == "XMLHttpRequest")));
        }

 

    }
}